package com.xzc.java8.A_lambda.lambda5;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

public class MethodRef {

    public static List<Apple> sort(Apple a1, Apple a2, Comparator<Apple> c) {
        List<Apple> list = new ArrayList<>();
        int out = c.compare(a1, a2);
        if (out >= 0) {
            list.add(a1);
            list.add(a2);
            return list;
        } else {
            list.add(a2);
            list.add(a1);
            return list;
        }
    }

    public static void thread(Runnable a) {
        a.run();
    }

    public static void main(String[] args) {
        Apple a1 = new Apple();
        Apple a2 = new Apple();
        sort(a1, a2, (a, b) -> a.getWeight() - b.getWeight());
        sort(a1, a2, Comparator.comparing(Apple::getWeight));

        thread(() -> Thread.currentThread().dumpStack());
        thread(Thread::dumpStack);

        List<String> str = Arrays.asList("a", "b");
        str.sort((s1, s2) -> s1.compareToIgnoreCase(s2));
        str.sort(String::compareToIgnoreCase);
    }
}
